package com.example.innovate.service.impl;

import com.example.innovate.domain.UserInfoDO;
import com.example.innovate.domain.UserInfoDOExample;
import com.example.innovate.mapper.UserInfoDOMapper;
import com.example.innovate.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserInfoDOMapper userInfoDOMapper;

    @Override
    public UserInfoDO getUserByName(String username) {
        UserInfoDOExample userInfoDOExample = new UserInfoDOExample();
        userInfoDOExample.createCriteria()
                .andUserInfoUserNameEqualTo(username);
        List<UserInfoDO> userInfoDO = userInfoDOMapper.selectByExample(userInfoDOExample);
        if(!userInfoDO.isEmpty()){
            return userInfoDO.get(0);
        }
        return null;
    }

    @Override
    public void addUser(UserInfoDO userInfoDO) {
        userInfoDOMapper.insertSelective(userInfoDO);

    }

    @Override
    public void updateUser(UserInfoDO userInfoDO) {
        userInfoDOMapper.updateByPrimaryKeySelective(userInfoDO);

    }
}
